#ifndef __DISTSENSORLIB_H__
#define __DISTSENSORLIB_H__

#include <Arduino.h>


#include "SPI.h"

#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>


		
  

		/*
		#define analogPin		0;
#define MAXTIMETOSTART	5;
#define CYCLETOSEND		6;
#define CYCLETOSAVE		3;
#define MOVEMENTUMBRAL	2;

#define INTERRUPTIONPIN 4;
#define STOPPIN			7;
#define STARTPIN		5;
#define CSPIN			6;
		*/




//#include <Firmata.h>


class DISTSENSORLib{
	public:
		
		bool StartSENSOR ();
		
		
		
		byte GetDistance();
		
		volatile int f_wdt;
		
		
		/*
		bool StartRFIDNFC(void);
		bool ConfigureSAM(void);
		uint8_t DetectTag(void);
		void PrintUIDTagDetected(void);
		*/
	private:
		
		bool	SEN5050;		//{SEN5050 = true SE USA AS5050, SEN5050 = false SE USA AS5055}
		
		byte analogPin;
		byte MAXTIMETOSTART;
		byte CYCLETOSEND;
		byte CYCLETOSAVE;
		byte MOVEMENTUMBRAL;

		byte INTERRUPTIONPIN;
		byte STOPPIN;
		byte STARTPIN;
		byte CSPIN;

		unsigned int result;
		unsigned int result1;
		unsigned int result2;
		unsigned int result3;
		unsigned int result4;



		float divisor;
		unsigned int mask;

		int LastAngle;
		int ActAngle;
		int tmpAngle;
		int LastPosition;
		int ActPosition;
		int LastDirection;
		int ActDirection;
		int TurnsCounter;
		float RealDistance;
		int ReferenceAngle;
		int lecturas;
		bool firstReads;
		double millisAnt;
		int estado;
		bool PhoneConected;
		byte TimeToSave;
		byte TimeToSend;
		
		void  IdentifyUser();
		void  WaitForUser();
		void  InitAll();
		bool  CheckIfStopped();
		void  SaveDataZb(byte newDataToSave);
		void  SendDataBT(byte newDataToSend);
		void  SendDataZigbee();
		void  DeinitWatchdog();
		void  InitWatchdog();
		void  enterSleep();


		/*
		uint8_t dataRX[35];//Receive buffer.
		uint8_t dataTX[35];//Transmit buffer.
		uint8_t _UID[4];// stores the UID (unique identifier) of a card.
		//uint8_t keyAccess[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } ;// stores the key or password.
		//uint8_t address = 0x04;//Address to read.
		uint8_t ATQ[2];//Answer to request
		uint8_t state;//state of the process
		uint8_t aux[16];//Auxiliar buffer. 
		void sendTX(uint8_t *_dataTX, uint8_t length, uint8_t outLength);
		void getACK(void);
		void waitResponse(void);
		void getData(uint8_t outLength);
		void checkSum(uint8_t *_dataTX);
		uint8_t lengthCheckSum(uint8_t *_dataTX);
		*/
};

#endif
